var STB_bill = function(){
    this.attribs = {
        ident: null,
        dbIdent: null,
        dateCreatedTimeStamp: null,
        dateCreated: null
    };
    this.init = function(){
        this.setIdent();
        this.setDateCreated();
        this.attribs.items = new Array();
        this.attribs.buyers = new Array();
    };
    
    this.mapToAttribs = function(billData){
        this.setDbIdent(billData.id_bil);
        this.setIdent(billData.id_local_bil);
        this.setName(billData.name_bil);
        this.setDateCreated(billData.date_create_bil);  
    };
    
    this.setName = function(name){
        if (typeof name != 'undefined' && name != null ) {
            this.attribs.name = name;
        } else {
            this.attribs.name = '';   
        }
    };
    
    this.getName = function(){
        return this.attribs.name;  
    };
    
    this.addItem  = function(item){
        this.attribs.items.push(item);  
    };
    
    this.getItem = function(ident){
        return utils.getArrItem(this.attribs.items, ident);  
    };
    
    this.removeItem = function(ident){
        utils.removeArrItem(this.attribs.items, ident);  
    };
    
    this.addBuyer = function(buyer){
        this.attribs.buyers.push(buyer);
    };
    
    this.getBuyer = function(ident){
        return utils.getArrItem(this.attribs.buyers, ident);  
    };
    
    this.removeBuyer = function(ident){
        utils.removeArrItem(this.attribs.buyers, ident);  
    };
    
    this.getBuyers = function(){
        return this.attribs.buyers;  
    };
    
    this.getItems = function(){
        return this.attribs.items;  
    };
    
    this.init();
};

STB_bill.prototype = new EngineModel;

var STB_order = function(){
    this.attribs = {
        ident: null,
        dbIdent: null,
        dateCreatedTimeStamp: null,
        dateCreated: null
    };
    this.init = function(){
        this.setIdent();
        this.setDateCreated();
        this.attribs.buyer = null;
        this.attribs.item = null; 
    };          
};

STB_order.prototype = new EngineModel;

var STB_item = function(){
    this.attribs = {
        ident: null,
        dbIdent: null,
        dateCreatedTimeStamp: null,
        dateCreated: null
    };
    this.init = function(){
        this.setIdent();
        this.setDateCreated();
        this.attribs.billId = '';
        this.attribs.name = '';
        this.attribs.qty = 1;
        this.attribs.price = 0.00;
        this.attribs.buyers = new Array();
    };
    
    this.setName = function(name){
        if (typeof name != 'undefined' && name != null ) {
            this.attribs.name = name;
        } else {
            this.attribs.name = '';
        }
    };
    
    this.setQty = function(qty){
        this.attribs.qty = qty;
    };
    
    this.setPrice = function(price){
        this.attribs.price = parseFloat(price);
    };
    
    this.setBillId = function(billId){
        this.attribs.billId = billId;
    };
    
    this.getBillId = function(){
        return this.attribs.billId;
    };
    
    this.getName = function(){
        return this.attribs.name;  
    };
    
    this.getPrice = function(){
        return this.attribs.price;  
    };
    
    this.getQty = function(){
        return this.attribs.qty;  
    };
    
    this.addBuyer = function(buyer){
        this.attribs.buyers.push(buyer);      
    };
    
    this.removeBuyer = function(ident){
        utils.removeArrItem(this.attribs.buyers, ident);  
    };
    
    this.getBuyer = function(ident){
        return utils.getArrItem(this.attribs.buyers, ident);  
    };
    
    this.getBuyers = function(){
        return this.attribs.buyers;  
    };
    
    this.init();
};

STB_item.prototype = new EngineModel;

var STB_buyer = function(){
    this.attribs = {
        ident: null,
        dbIdent: null,
        dateCreatedTimeStamp: null,
        dateCreated: null
    };
    this.init = function(){
        this.setIdent();
        this.setDateCreated();
        this.attribs.name = '';
        this.attribs.billId = '';
        this.attribs.items = new Array();
    };
    
    this.setName = function(name){
        if (typeof name != 'undefined' && name != null ) {
            this.attribs.name = name;
        } else {
            this.attribs.name = '';
        }
    };
    
    this.setBillId = function(billId){
        this.attribs.billId = billId;
    };
    
    this.getBillId = function(){
        return this.attribs.billId;
    };
    
    this.getName = function(){
        return this.attribs.name;  
    };
    
    this.addItem = function(item){
        this.attribs.items.push(item);  
    };
    
    this.removeItem = function(ident){
        utils.removeArrItem(this.attribs.items, ident);  
    };
    
    this.getItem = function(ident){
        utils.getArrItem(this.attribs.items, ident);  
    };
    
    this.getItems = function(){
        return this.attribs.items;  
    };
    
    this.mapToAttribs = function(personData){
        this.setDbIdent(personData.id_per);
        this.setIdent(personData.id_local_per);
        this.setBillId(personData.id_bil);
        this.setName(personData.name_per);
        this.setDateCreated(personData.date_create_per);  
    };
    
    this.init();
};

STB_buyer.prototype = new EngineModel;
/*
for(var i=0; i<10;i++){
    console.log(new STB_item().getIdent());
}
*/